package org.chen.wordwave.base.ui;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.chen.wordwave.R;

public class CustomActionBar extends LinearLayout {

    private ImageView headerBack;
    private TextView headerTitle, headerMenuText;
    private LinearLayout llSearch;
    private LayoutInflater mInflater;
    private View headView;

    public CustomActionBar(Context context) {
        super(context);
        init(context);
    }

    public CustomActionBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public void init(Context context) {
        mInflater = LayoutInflater.from(context);
        headView = mInflater.inflate(R.layout.customactionbar, null);
        addView(headView);
        initView();
    }

    private void initView() {
        headerBack = headView.findViewById(R.id.header_back);
        headerTitle = headView.findViewById(R.id.header_title);
        headerMenuText = headView.findViewById(R.id.header_menu);
        llSearch = headView.findViewById(R.id.ll__search);
        headerBack.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity) getContext()).finish();
            }
        });
    }

    public void setStyle(String title) {
        if (title != null)
            headerTitle.setText(title);
    }

    public void setStyle(boolean hasSearch){
        if(hasSearch){
            llSearch.setVisibility(VISIBLE);
        }
    }

    public void setStyleNoBack(String title) {
        setStyle(title);
    }

}
